<?php
/*
 * Team 1 Project - Palo Alto Bicycle Club
 * Author: Archana Nagarkatti
 * Class: COIN 71
 * Filename: writeXML.php
 * Date Created: 3/19/2009
 * Functionality: Writes the latest announcement post field values to XML
 * Modification History:
*/

	$XML_FILE = "announcements.xml";
	$dom = new DOMDocument;
	$dom->formatOutput = true;
	$dom->load($XML_FILE);
	$announcementsEl = $dom->getElementsByTagName('announcements')->item(0);

	//create announcement element
	$announceEl = $dom ->createElement('announcement');
	$announcementsEl -> appendChild($announceEl);

	//create title element
	addChildWText($dom,  $announceEl, "title", $_POST["title"]);
	//create postedby element
	addChildWText($dom,  $announceEl, "author", $_POST["author"]);
	//create message element
	addChildWText($dom,  $announceEl, "message", $_POST["message"]);
	//create post_date element
	addChildWText($dom,  $announceEl, "postdate", date('m/d/Y'));

	//save XML file with newly posted information.
	$test = $dom->save($XML_FILE);

	//redirects to the home page (Tyler's page) after posting message to XML file
	$redirectURL = "Location:http://";
	$redirectURL .= $_SERVER['HTTP_HOST'];
	$redirectURL .= "/~mazaika/pabc/public_3_16_09/home.php";
	header($redirectURL);


	// reusing code in read_library.php
	// adds a child node "tagName" with "text" to "parent" in "document"
	function addChildWText ( $document, $parent, $tagName, $text ) {
		$newTag = $document->createElement( $tagName );
		$newTag->appendChild( $document->createTextNode( $text ));
		$parent->appendChild( $newTag );
	}
?>